package com.fansl.allround.study.designpattern.responsibilitychain;

/**
 * @author fansl
 * @Description: 具体处理者
 * @date 2019/10/11 13:43
 */
public class CEOLeaveNoteHandler extends Handler {
    public CEOLeaveNoteHandler(){
    }

    /**
     * 当前处理者是否可以处理
     *
     * @param request
     * @return
     */
    @Override
    protected boolean canHandle(Request request) {
        if(request instanceof LeaveNoteRequest){
            LeaveNoteRequest request1 = (LeaveNoteRequest) request;
            return request1.getLeaveDays()>3;
        }
        return false;
    }

    /**
     * 每个处理者必须实现处理的任务
     *
     * @param request
     * @return
     */
    @Override
    protected Response process(Request request) {
        if(request instanceof LeaveNoteRequest){
            LeaveNoteRequest request1 = (LeaveNoteRequest) request;
            String result = String.format("[%s]同意[%s]请假[%d]天的请求","CEO",request1.getName(),request1.getLeaveDays());
            LeaveNoteResponse leaveNoteResponse = new LeaveNoteResponse();
            leaveNoteResponse.setResult(result);
            return leaveNoteResponse;
        }
        return null;
    }
}
